<cfoutput>
	<cfif IsUserLoggedIn() and IsDefined("request.scholar") and request.scholar.Scholarship_ID gt 0>
	
		<cfscript>
			scholarshipGateway = new assets.calgrants.com.gateway.ScholarshipGateway();
			scholarship = scholarshipGateway.get(Scholarship_ID = GetAuthUser());
			base = new assets.calgrants.com.Base();
			storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
			institutions = storedProcedureGateway.call("getDistinctInstitutions");
			states = storedProcedureGateway.call("getDistinctStates");
		</cfscript>

		<script type="text/javascript" language="javascript">
		<!--
			<cfoutput>
				var institution1ID = "#scholarship.getInstitution1_ID()#";
				var institution2ID = "#scholarship.getInstitution2_ID()#";
				var institution3ID = "#scholarship.getInstitution3_ID()#";
			</cfoutput>
			
			var validateAttendanceLevel = function() {
				if ($("##Attendance_Level").val() == "Part-time") {
					alert("To receive this scholarship, you must attend your college/university at least half\-time");
				}
			};
			
			var validateDegreeLevel = function() {
				if ($("##Degree_Level").val() == "Certificate") {
					alert("To receive this scholarship, you must pursue a Bachelor\'s or Associate\'s degree");
				}
			};
		
			var validate = function() {
				var errors = "";
				var valid = true;
				try {
					if ($("##New_Institution1").is(":checked")) {
						if ($("##Institution1_Institution").val().length == 0) {
							valid = false;
							errors += "College\/University Name is required for the primary college\/university\n";
						}
						if ($("##Institution1_FAO_Address1").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office Address is required for the primary college\/university\n";
						}
						if ($("##Institution1_FAO_City").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office City is required for the primary college\/university\n";
						}
						if ($("##Institution1_FAO_State").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office State is required for the primary college\/university\n";
						}
						if ($("##Institution1_FAO_Zip_Code").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office Zip Code is required for the primary college\/university\n";
						}
						if ($("##Institution1_FAO_Phone").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office Phone is required for the primary college\/university\n";
						}
					} else if ($("##Institution1_ID").val() == 0) {
						valid = false;
						errors += "Primary College\/University is required";
					}
					if ($("##New_Institution2").is(":checked")) {
						if ($("##Institution2_Institution").val().length == 0) {
							valid = false;
							errors += "College\/University Name is required for the secondary college\/university\n";
						}
						if ($("##Institution2_FAO_Address1").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office Address is required for the secondary college\/university\n";
						}
						if ($("##Institution2_FAO_City").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office City is required for the secondary college\/university\n";
						}
						if ($("##Institution2_FAO_State").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office State is required for the secondary college\/university\n";
						}
						if ($("##Institution2_FAO_Zip_Code").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office Zip Code is required for the secondary college\/university\n";
						}
						if ($("##Institution2_FAO_Phone").val().length == 0) {
							valid = false;
							errors += "Financial Aid Office Phone is required for the secondary college\/university\n";
						}
						if (!valid) {
							//errors += "\nSecondary college warning";
							errors += "\n\nIf you do not have a secondary college\/university, uncheck \"My secondary college\/university is not listed\".";
						}
					}
				}
				catch(err) {
					alert(err);
					valid = false;
				}
				if (!valid) {
					alert(errors);
				}
				return valid;				
			}
			
			var toggleInstitution1 = function() {
				if ($("##New_Institution1").is(":checked")) {
					$("##institution1Container").hide();
					$("##institution1FormContainer").show();
					$("##Institution1_ID").val(0);	
				} else {
					$("##institution1FormContainer").hide();
					$("##institution1Container").show();
					$("##Institution1_Institution").val("");
					$("##Institution1_FAO_Address1").val("");
					$("##Institution1_FAO_City").val("");
					$("##Institution1_FAO_State").val("");
					$("##Institution1_FAO_Zip_Code").val("");
					$("##Institution1_FAO_Phone").val("");
					$("##Institution1_ID").val(institution1ID);
				}
			}
			var toggleInstitution2 = function() {
				if ($("##New_Institution2").is(":checked")) {
					$("##institution2Container").hide();
					$("##institution2FormContainer").show();
					$("##Institution2_ID").val(0);	
				} else {
					$("##institution2FormContainer").hide();
					$("##institution2Container").show();
					$("##Institution2_Institution").val("");
					$("##Institution2_FAO_Address2").val("");
					$("##Institution2_FAO_City").val("");
					$("##Institution2_FAO_State").val("");
					$("##Institution2_FAO_Zip_Code").val("");
					$("##Institution2_FAO_Phone").val("");
					$("##Institution2_ID").val(institution2ID);
				}
			}
			var validateInstitution2 = function() {
				if ($("##Institution2_ID").val() == $("##Institution1_ID").val() && $("##Institution2_ID").val() !== 0) {
					alert("Institution 1 and 2 must be different colleges/universities");
					$("##Institution2_ID").val(0);
				} else if ($("##Institution1_ID").val() == 0 && $("##Institution2_ID").val() > 0) {
					alert("Select Institution 1 before selecting Institution 2");
					$("##Institution2_ID").val(0);
				}
			}
			$(function() {
				var enrollmentDatePicker = $("##Enrollment_Date").kendoDatePicker().data("kendoDatePicker");
			})
		//-->
		</script>
	
		<cfform name="scholarInstitutionForm" id="scholarInstitutionForm" action="#script_name#" method="post" onsubmit="return validate();">
			<cfinput type="hidden" name="action" value="saveScholar" />
			<cfinput type="hidden" name="Scholarship_ID" value="#GetAuthUser()#" />
			<cfif IsDate(request.scholar.Claim_Date)>
				<cfinput type="hidden" name="view" value="#view#" />
			<cfelse>
				<cfinput type="hidden" name="view" value="editScholarBanking" />
			</cfif>
			<div class="row">
				<div class="span6">
					<label class="required">Primary College/University</label>
					<!--- Institution 1 --->
					<div class="well well-small clearfix" style="margin-right: 20px;">
						<label class="checkbox">
							<cfinput type="checkbox" name="New_Institution1" value="true" onClick="toggleInstitution1();"> 
							My primary college/university is not listed
						</label>
						<div id="institution1Container" style="margin-top: 10px;">
							<cfselect name="Institution1_ID" required="yes" message="Primary College/University is required" style="width: 350px;">
								<option value="0" selected>Select...</option>
								<cfloop query="institutions">
									<option value="#Institution_ID#"<cfif scholarship.getInstitution1_ID() eq Institution_ID> selected</cfif>>#Display#</option>
								</cfloop>
							</cfselect>
						</div>
						<div id="institution1FormContainer" style="display: none; margin-top: 10px;">
							<div class="clearfix">
								<label class="required">College/University Name</label>
								<cfinput type="text" name="Institution1_Institution" value="" maxlength="200" style="width: 350px;" autocomplete="off">
							</div>
							<div class="clearfix">
								<label class="required">Financial Aid Office Address</label>
								<cfinput type="text" name="Institution1_FAO_Address1" value="" maxlength="200" style="width: 350px;" autocomplete="off">
							</div>
							<div class="clearfix">
								<label class="required">Financial Aid Office City</label>
								<cfinput type="text" name="Institution1_FAO_City" value="" maxlength="100" style="width: 350px;" autocomplete="off">
							</div>
							<div class="clearfix">
								<label class="required">Financial Aid Office State</label>
								<cfselect name="Institution1_FAO_State" query="states" display="State" value="Code" style="width: auto;" queryPosition="below">
									<option value="">Select...</option>
								</cfselect>
							</div>
							<div class="clearfix">
								<label class="required">Financial Aid Office Zip Code</label>
								<cfinput type="text" name="Institution1_FAO_Zip_Code" value="" validate="zipcode" message="Financial Aid Office Zip Code must be a valid zip code" maxlength="5" style="width: 150px;" autocomplete="off">
							</div>
							<div class="clearfix">
								<label class="required">Financial Aid Office Phone</label>
								<cfinput type="text" name="Institution1_FAO_Phone" value="" validate="telephone" message="Financial Aid Office Phone must be a valid phone number" maxlength="12" placeholder="######-######-########" style="width: 350px;" autocomplete="off">
							</div>
						</div>
					</div>
					<!--- Institution 2 --->
					<div style="display: block;">
						<label class="required">Secondary College/University (optional)</label>
						<div class="well well-small clearfix" style="margin-right: 20px;">
							
							<label class="checkbox">
								<cfinput type="checkbox" name="New_Institution2" value="true" onClick="toggleInstitution2();"> 
								My secondary college/university is not listed
							</label>
							<div id="institution2Container" style="margin-top: 10px;">
								<cfselect name="Institution2_ID" onChange="validateInstitution2();" style="width: 350px;">
									<option value="0" selected>Select...</option>
									<cfloop query="institutions">
										<option value="#Institution_ID#"<cfif scholarship.getInstitution2_ID() eq Institution_ID> selected</cfif>>#Display#</option>
									</cfloop>
								</cfselect>
							</div>
							<div id="institution2FormContainer" style="display: none; margin-top: 10px;">
								<div class="clearfix">
									<label class="required">College/University Name</label>
									<cfinput type="text" name="Institution2_Institution" value="" maxlength="200" style="width: 350px;" autocomplete="off">
								</div>
								<div class="clearfix">
									<label class="required">Financial Aid Office Address</label>
									<cfinput type="text" name="Institution2_FAO_Address1" value="" maxlength="200" style="width: 350px;" autocomplete="off">
								</div>
								<div class="clearfix">
									<label class="required">Financial Aid Office City</label>
									<cfinput type="text" name="Institution2_FAO_City" value="" maxlength="100" style="width: 350px;" autocomplete="off">
								</div>
								<div class="clearfix">
									<label class="required">Financial Aid Office State</label>
									<cfselect name="Institution2_FAO_State" query="states" display="State" value="Code" style="width: auto;" queryPosition="below">
										<option value="">Select...</option>
									</cfselect>
								</div>
								<div class="clearfix">
									<label class="required">Financial Aid Office Zip Code</label>
									<cfinput type="text" name="Institution2_FAO_Zip_Code" value="" validate="zipcode" message="Financial Aid Office Zip Code must be a valid zip code" maxlength="5" style="width: 150px;" autocomplete="off">
								</div>
								<div class="clearfix">
									<label class="required">Financial Aid Office Phone</label>
									<cfinput type="text" name="Institution2_FAO_Phone" value="" validate="telephone" message="Financial Aid Office Phone must be a valid phone number" maxlength="12" placeholder="######-######-########" style="width: 350px;" autocomplete="off">
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="span6">
					<div class="clearfix">
						<label class="required">Attendance Level</label>
						<span class="help-block">Indicate your attendance level. Total units from all colleges/universities.</span>
						<cfselect name="Attendance_Level" required="yes" message="Attendance Level is required" onChange="validateAttendanceLevel();" style="width: 350px;">
							<option value="">Select...</option>
							<option value="Full-time"<cfif scholarship.getAttendance_Level() eq "Full-time"> selected</cfif>>Full-time (12 or more units)</option>
							<option value="Half-time"<cfif scholarship.getAttendance_Level() eq "Half-time"> selected</cfif>>Half-time (6 to 11 units)</option>
							<option value="Part-time"<cfif scholarship.getAttendance_Level() eq "Part-time"> selected</cfif>>Less than half-time (less than 6 units)</option>
						</cfselect>
					</div>
					<div class="clearfix">
						<label class="required">Degree Goal</label>
						<span class="help-block">Most advanced degree between all colleges/universities.</span>
						<cfselect name="Degree_Level" required="yes" message="Degree Level is required" onChange="validateDegreeLevel();" style="width: 350px;">
							<option value="">Select...</option>
							<option value="Bachelors"<cfif scholarship.getDegree_Level() eq "Bachelors"> selected</cfif>>Bachelor's</option>
							<option value="Associates"<cfif scholarship.getDegree_Level() eq "Associates"> selected</cfif>>Associate's</option>
							<option value="Certificate"<cfif scholarship.getDegree_Level() eq "Certificate"> selected</cfif>>Certificate</option>
						</cfselect>
					</div>
					<div class="kendo-control clearfix">
						<label class="required">Enrollment Date</label>
						<span class="help-block">Enter the date you will sign-up for classes at your primary college/university.</span>
						<cfinput type="text" maxlength="10" name="Enrollment_Date" value="#DateFormat(scholarship.getEnrollment_Date(), 'm/d/yyyy')#" placeholder="m/d/yyyy" required="yes" validate="date" message="Enrollment Date is required and must be a valid date" style="width: 120px" autocomplete="off" />
					</div>
				</div>
			</div>
			<div class="row">
				<div class="span12">
					<div style="margin-bottom: 20px;">
						<cfif GetUserRoles() eq "scholar">
							<cfinput type="submit" name="saveButton" class="btn btn-primary" value="Save" />
						<cfelse>
							<a href="?view=editScholarProfile" class="btn btn-primary">Back</a>
							<button type="submit" name="continueButton" class="btn btn-primary">Continue</button>
						</cfif>
					</div>
				</div>
			</div>
		</cfform>
	<cfelse>
		<div class="row">
			<div class="span12">
				<div class="alert alert-info notFound">Scholarship not found</div>
			</div>
		</div>
	</cfif>
</cfoutput>